/**
 @file sys_usw_serdes_api.h

 @author  Copyright (C) 2018 Centec Networks Inc.  All rights reserved.

 @date 2023-10-08

 @version v1.0

*/

#ifndef _SYS_USW_SERDES_API_H
#define _SYS_USW_SERDES_API_H
#ifdef __cplusplus
extern "C" {
#endif

/****************************************************************
 *
 * Header Files
 *
 ***************************************************************/
#include "sal.h"
#include "ctc_port.h"

/****************************************************************
*
* Defines and Macros
*
****************************************************************/

#ifdef EMULATION_ENV
#define MCHIP_SERDES_CB(cb_function, lchip, ...)\
        do {\
            if(MCHIP_SERDES(lchip)->cb_function)\
            {\
                CTC_ERROR_RETURN(MCHIP_SERDES(lchip)->cb_function(lchip, ##__VA_ARGS__));\
            }\
        } while (0)
#else
#define MCHIP_SERDES_CB(cb_function, lchip, ...)\
    do {\
        if(MCHIP_SERDES(lchip)->cb_function)\
        {\
            CTC_ERROR_RETURN(MCHIP_SERDES(lchip)->cb_function(lchip, ##__VA_ARGS__));\
        }\
        else return CTC_E_INVALID_PTR;\
    } while (0)
#endif

/****************************************************************
*
* Functions
*
****************************************************************/
int32 sys_usw_dmps_serdes_set_group_init(uint8 lchip, uint16 grp);
int32 sys_usw_dmps_serdes_set_lane_init(uint8 lchip, uint16 serdes);
int32 sys_usw_dmps_serdes_set_lane_speed(uint8 lchip, uint16 serdes, uint8 dir, uint8 spd);
int32 sys_usw_dmps_serdes_set_group_speed(uint8 lchip, uint16 grp, uint8 grp_spd);
int32 sys_usw_dmps_serdes_set_lane_fw_load(uint8 lchip, uint16 serdes, void* p_fw);
int32 sys_usw_dmps_serdes_set_group_fw_load(uint8 lchip, uint16 grp, void* p_fw);
int32 sys_usw_dmps_serdes_set_lane_power(uint8 lchip, uint16 serdes, uint8 dir, uint8 pw_up);
int32 sys_usw_dmps_serdes_set_group_power(uint8 lchip, uint16 grp, uint8 pw_up);
int32 sys_usw_dmps_serdes_set_lane_en(uint8 lchip, uint16 serdes, uint8 dir, uint8 en);
int32 sys_usw_dmps_serdes_set_lane_rst(uint8 lchip, uint16 serdes, uint8 dir, uint8 rst_level, uint8 rst_val);
int32 sys_usw_dmps_serdes_set_rx_force_sigdet(uint8 lchip, uint16 serdes, uint8 fc_up);
int32 sys_usw_dmps_serdes_set_rx_sigdet_thrd(uint8 lchip, uint16 serdes, uint8 thrd_mv);
int32 sys_usw_dmps_serdes_set_tx_eq_force(uint8 lchip, uint16 serdes, void* p_ffe);
int32 sys_usw_dmps_serdes_set_lane_prbs_test_pattern(uint8 lchip, uint16 serdes, uint8 dir, uint8 pattern);
int32 sys_usw_dmps_serdes_set_lane_prbs_test_en(uint8 lchip, uint16 serdes, uint8 dir, uint8 en);
int32 sys_usw_dmps_serdes_set_lane_prbs_test_rst(uint8 lchip, uint16 serdes);
int32 sys_usw_dmps_serdes_set_lane_prbs_test_run(uint8 lchip, uint16 serdes, uint32 duration_ms, void* p_prbs);
int32 sys_usw_dmps_serdes_set_rx_ctle_force(uint8 lchip, uint16 serdes, void* p_ctle);
int32 sys_usw_dmps_serdes_set_rx_dfe_force(uint8 lchip, uint16 serdes, uint32* dfe);
int32 sys_usw_dmps_serdes_set_rx_ffe_force(uint8 lchip, uint16 serdes, uint32* ffe_rx);
int32 sys_usw_dmps_serdes_set_rx_ctle_en(uint8 lchip, uint16 serdes, uint8 en);
int32 sys_usw_dmps_serdes_set_rx_dfe_en(uint8 lchip, uint16 serdes, uint8 en);
int32 sys_usw_dmps_serdes_set_rx_ffe_en(uint8 lchip, uint16 serdes, uint8 en);
int32 sys_usw_dmps_serdes_set_lane_loopback(uint8 lchip, uint16 serdes, void* p_lpbk);
int32 sys_usw_dmps_serdes_set_lane_polarity(uint8 lchip, uint16 serdes, uint8 dir, uint8 pol);
int32 sys_usw_dmps_serdes_set_lane_err_inj(uint8 lchip, uint16 serdes, uint8 err_num);
int32 sys_usw_dmps_serdes_set_rx_train_en(uint8 lchip, uint16 serdes, uint8 en);
int32 sys_usw_dmps_serdes_set_tx_train_en(uint8 lchip, uint16 serdes, uint8 en);
int32 sys_usw_dmps_serdes_set_rx_cdr_det_en(uint8 lchip, uint16 serdes, uint8 en);
int32 sys_usw_dmps_serdes_set_lane_precode(uint8 lchip, uint16 serdes, uint8 dir, uint8 en);
int32 sys_usw_dmps_serdes_set_lane_graycode(uint8 lchip, uint16 serdes, uint8 dir, uint8 en);
int32 sys_usw_dmps_serdes_set_lane_msblsb(uint8 lchip, uint16 serdes, uint8 dir, uint8 value);
int32 sys_usw_dmps_serdes_set_group_reg(uint8 lchip, uint16 grp, uint32 addr, uint32 mask, uint32 data);
int32 sys_usw_dmps_serdes_set_lane_reg(uint8 lchip, uint16 serdes, uint32 addr, uint32 mask, uint32 data);
int32 sys_usw_dmps_serdes_set_fw_cmd(uint8 lchip, uint16 fw_id, void* fw_cmd);

int32 sys_usw_dmps_serdes_get_lane_speed(uint8 lchip, uint16 serdes, uint8 dir, uint8* p_spd);
int32 sys_usw_dmps_serdes_get_lane_fw_version(uint8 lchip, uint16 serdes, void* p_fw_ver);
int32 sys_usw_dmps_serdes_get_group_fw_version(uint8 lchip, uint16 grp, void* p_fw_ver);
int32 sys_usw_dmps_serdes_get_lane_fw_stat(uint8 lchip, uint16 serdes, uint8* p_stat);
int32 sys_usw_dmps_serdes_get_group_fw_stat(uint8 lchip, uint16 serdes, uint8* p_stat);
int32 sys_usw_dmps_serdes_get_group_pll_lock(uint8 lchip, uint16 serdes, uint8* p_pll_lock);
int32 sys_usw_dmps_serdes_get_lane_pll_lock(uint8 lchip, uint16 serdes, uint8 dir, uint8* p_pll_lock);
int32 sys_usw_dmps_serdes_get_rx_sigdet(uint8 lchip, uint16 serdes, uint8* p_sig_det);
int32 sys_usw_dmps_serdes_get_rx_sigdet_thrd(uint8 lchip, uint16 serdes, uint32* p_thrd_mv);
int32 sys_usw_dmps_serdes_get_rx_force_sigdet(uint8 lchip, uint16 serdes, uint8* p_is_fc, uint8* p_sigdet);
int32 sys_usw_dmps_serdes_get_rx_ready(uint8 lchip, uint16 serdes, uint8* p_rdy);
int32 sys_usw_dmps_serdes_get_lane_en(uint8 lchip, uint16 serdes, uint8 dir, uint8* p_en);
int32 sys_usw_dmps_serdes_get_lane_rst(uint8 lchip, uint16 serdes, uint8 rst_level, uint8* p_rst);
int32 sys_usw_dmps_serdes_get_tx_eq(uint8 lchip, uint16 serdes, void* p_ffe);
int32 sys_usw_dmps_serdes_get_lane_prbs_test_pattern(uint8 lchip, uint16 serdes, uint8 dir, uint8* p_pattern);
int32 sys_usw_dmps_serdes_get_lane_prbs_test_en(uint8 lchip, uint16 serdes, uint8 dir, uint8* p_en);
int32 sys_usw_dmps_serdes_get_lane_prbs_test_cnt(uint8 lchip, uint16 serdes, void* p_prbs);
int32 sys_usw_dmps_serdes_get_rx_ctle(uint8 lchip, uint16 serdes, void* p_ctle);
int32 sys_usw_dmps_serdes_get_rx_dfe(uint8 lchip, uint16 serdes, uint32* dfe);
int32 sys_usw_dmps_serdes_get_rx_ffe(uint8 lchip, uint16 serdes, uint32* ffe_rx);
int32 sys_usw_dmps_serdes_get_rx_ctle_en(uint8 lchip, uint16 serdes, uint8* p_en);
int32 sys_usw_dmps_serdes_get_rx_dfe_en(uint8 lchip, uint16 serdes, uint8* p_en);
int32 sys_usw_dmps_serdes_get_rx_ffe_en(uint8 lchip, uint16 serdes, uint8* p_en);
int32 sys_usw_dmps_serdes_get_lane_loopback(uint8 lchip, uint16 serdes, void* p_lpbk);
int32 sys_usw_dmps_serdes_get_lane_polarity(uint8 lchip, uint16 serdes, uint8 dir, uint8* p_pol);
int32 sys_usw_dmps_serdes_get_lane_power(uint8 lchip, uint16 serdes, uint8 dir, uint8* p_pw_up);
int32 sys_usw_dmps_serdes_get_group_power(uint8 lchip, uint16 serdes, uint8* p_pw_up);
int32 sys_usw_dmps_serdes_get_rx_train_stat(uint8 lchip, uint16 serdes, uint8* p_en, uint8* p_stat, uint32* p_reason);
int32 sys_usw_dmps_serdes_get_tx_train_stat(uint8 lchip, uint16 serdes, uint8* p_en, uint8* p_stat, uint32* p_reason);
int32 sys_usw_dmps_serdes_get_rx_eye_open(uint8 lchip, uint16 serdes, uint8 wh_sel, uint32* p_eo_margin);
int32 sys_usw_dmps_serdes_get_rx_eye_plot(uint8 lchip, uint16 serdes, uint32* p_eye_data);
int32 sys_usw_dmps_serdes_get_rx_cdr_det_en(uint8 lchip, uint16 serdes, uint8* p_en);
int32 sys_usw_dmps_serdes_get_rx_cdr_lock(uint8 lchip, uint16 serdes, uint8* p_is_lock);
int32 sys_usw_dmps_serdes_get_rx_snr(uint8 lchip, uint16 serdes, uint32* p_snr_db);
int32 sys_usw_dmps_serdes_get_lane_reg(uint8 lchip, uint16 serdes, uint32 addr, uint32 mask, uint32* p_data);
int32 sys_usw_dmps_serdes_get_group_reg(uint8 lchip, uint16 grp, uint32 addr, uint32 mask, uint32* p_data);
int32 sys_usw_dmps_serdes_dbg_info(uint8 lchip, uint16 serdes, uint32 dbg_in, uint32* dbg_out);
int32 sys_usw_dmps_serdes_get_lane_precode(uint8 lchip, uint16 serdes, uint8 dir, uint8* p_en);
int32 sys_usw_dmps_serdes_get_lane_graycode(uint8 lchip, uint16 serdes, uint8 dir, uint8* p_en);
int32 sys_usw_dmps_serdes_get_lane_msblsb(uint8 lchip, uint16 serdes, uint8 dir, uint8* p_value);
int32 sys_usw_dmps_serdes_set_rx_optical_mode(uint8 lchip, uint16 serdes, uint8 en);
int32 sys_usw_dmps_serdes_get_rx_optical_mode(uint8 lchip, uint16 serdes, uint8* p_en);
int32 sys_usw_dmps_serdes_get_lane_port_info(uint8 lchip, uint16 serdes, void* p_lane_port);
int32 sys_usw_dmps_serdes_api_set_property(uint8 lchip, ctc_chip_property_t chip_prop, void* p_value);
int32 sys_usw_dmps_serdes_api_get_property(uint8 lchip, ctc_chip_property_t chip_prop, void* p_value);

#ifdef __cplusplus
}
#endif

#endif

